package com.xigua._查找;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/3/719:05
 */
public class _剑指Offer04_二维数组中的查找 {

    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                if (matrix[i][j] == target) return true;
            }
        }
        return false;
    }

    public boolean findNumberIn2DArray1(int[][] matrix, int target) {
        if (matrix == null ||matrix.length ==0 || matrix[0].length ==0  ) return false;
        int x = matrix[0].length-1;
        int y = 0;
        while (x >=0 && y<matrix.length){
            int num = matrix[y][x];
            if (num == target){
                return true;
            }else if (target>num) {
                y++;
            }else{
                x--;
            }
        }
        return false;
    }

    public static void main(String[] args) {

    }



}
